fs = require("fs");
const readline = require("readline");

async function readFileLine({ filePath, getRow }) {
  const fileStream = fs.createReadStream(filePath);

  const rl = readline.createInterface({
    input: fileStream,
    crlfDelay: Infinity,
  });
  // 注意：使用 crlfDelay 选项
  // 将 xx.xx 中的所有 CR LF ('\r\n') 实例识别为单个换行符。
  let ri = 0;
  for await (const line of rl) {
    await getRow(line, ri);
    ri++;
  }
  return ri;
}

module.exports = readFileLine;
